﻿/*
 * OpenDoPE Word Add-In
 * Copyright (C) 2010-2011  Plutext Pty Ltd
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
 * 
 * For details, see http://www.gnu.org/licenses/gpl-2.0.html
 */

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using NLog;

using Word = Microsoft.Office.Interop.Word;


namespace OpenDoPE_Wed
{
    /// <summary>
    /// The form we display for a virgin content control
    /// (ie one which isn't bound, nor having a repeat/conditional).
    /// </summary>
    public partial class SdtUndoped : UserControl
    {
        static Logger log = LogManager.GetLogger("OpenDoPE_Wed");

        public SdtUndoped(Word.ContentControl cc)
        {
            InitializeComponent();

            this.sdtDetails.populate(cc);

            // Don't show bind option if its an SdtRow or SdtCell
            // Could use range.Information calculations that we
            // use in VBA, but simpler
            //log.Debug(cc.Range.WordOpenXML);
            if (cc.Range.WordOpenXML.Contains("<w:tbl>"))
            {
                log.Debug("SdtRow or SdtCell detected.");
                buttonBind.Hide();
            }
            // Don't show component adder if in a table
            object info = cc.Range.get_Information(Word.WdInformation.wdWithInTable);
            log.Debug("Object is: " + info.GetType().FullName);
            if ((Boolean)info)
            {
                buttonComponent.Hide();
            }

        }

        private void buttonBind_Click(object sender, EventArgs e)
        {
            ((WedTaskPane)this.Parent).displayBindForm(true);
        }

        private void buttonRepeat_Click(object sender, EventArgs e)
        {
            ((WedTaskPane)this.Parent).displayRepeatForm();

        }

        private void buttonNewCondition_Click(object sender, EventArgs e)
        {
            ((WedTaskPane)this.Parent).displaySimpleConditionMakerForm();

        }

        private void buttonConditionEditor_Click(object sender, EventArgs e)
        {
            ((WedTaskPane)this.Parent).displayConditionForm();

        }

        private void buttonComponent_Click(object sender, EventArgs e)
        {
            ((WedTaskPane)this.Parent).displayComponentForm();
        }
    }
}
